

#import "ViewController.h"
#import "LBSplashViewController.h"
#import "LBNativeViewController.h"
#import "LBRewardViewController.h"
#import "LBBannerViewController.h"
#import "LBInterstitialViewController.h"
#import "LBFullVideoViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *mainTableView;

@property (nonatomic, strong) NSArray *dataArray;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = [NSString stringWithFormat:@"六瓣 广告聚合 Demo"];
    self.view.backgroundColor = [UIColor whiteColor];

    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];

    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    self.dataArray = @[@"开屏广告", @"原生广告", @"Banner广告",@"激励视频",@"插屏广告",@"全屏视频"];
    [self.mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:self.mainTableView];
}

- (UITableView *)mainTableView{
    if (!_mainTableView) {
        _mainTableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _mainTableView.delegate = self;
        _mainTableView.dataSource = self;
        _mainTableView.backgroundColor = [UIColor colorWithRed:225/255.0 green:233/255.0 blue:239/255.0 alpha:1];
        _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _mainTableView;
}

#pragma make - UITableViewDelegate,UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 48;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithRed:225/255.0 green:233/255.0 blue:239/255.0 alpha:1];
    cell.contentView.backgroundColor = [UIColor colorWithRed:225/255.0 green:233/255.0 blue:239/255.0 alpha:1];
    NSString *title = [self.dataArray objectAtIndex:indexPath.row];

    cell.contentView.clipsToBounds = YES;
    cell.contentView.clipsToBounds = YES;
    cell.clipsToBounds = YES;
    cell.contentView.layer.cornerRadius = 6;
    cell.layer.cornerRadius = 6;
    UIView *view = [cell.contentView viewWithTag:999];
    if (view) {
        [view removeFromSuperview];
    }
    
    UILabel *labTitle = [[UILabel alloc]init];
    labTitle.backgroundColor = [UIColor whiteColor];
    labTitle.textColor= [UIColor blackColor];
    labTitle.textAlignment = NSTextAlignmentCenter;
    labTitle.tag = 999;
    labTitle.text = title;
    labTitle.clipsToBounds = YES;
    [cell.contentView addSubview:labTitle];
    labTitle.frame = CGRectMake(16, 8, self.view.bounds.size.width - 32, 32);
    labTitle.layer.cornerRadius = 4;
    labTitle.layer.borderWidth = 1;
    labTitle.layer.shadowColor = [UIColor darkGrayColor].CGColor;
    labTitle.layer.shadowOffset = CGSizeMake(0, 1);
    labTitle.layer.shadowOpacity = 1;
    
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 48;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    switch (indexPath.row) {
        case 0: {
            [self.navigationController pushViewController:[[LBSplashViewController alloc] initWithTitle:self.dataArray[indexPath.row]]  animated:YES];
            break;
        }
        case 1: {
            [self.navigationController pushViewController:[[LBNativeViewController alloc] initWithTitle:self.dataArray[indexPath.row]]  animated:YES];
            break;
        }
        case 2: {
            [self.navigationController pushViewController:[[LBBannerViewController alloc] initWithTitle:self.dataArray[indexPath.row]]  animated:YES];
            break;
        }
        case 3: {
            [self.navigationController pushViewController:[[LBRewardViewController alloc] initWithTitle:self.dataArray[indexPath.row]]  animated:YES];
            break;
        }
        case 4: {
            [self.navigationController pushViewController:[[LBInterstitialViewController alloc] initWithTitle:self.dataArray[indexPath.row]]  animated:YES];
            break;
        }
        case 5: {
            [self.navigationController pushViewController:[[LBFullVideoViewController alloc] initWithTitle:self.dataArray[indexPath.row]]  animated:YES];
            break;
        }
        default:
            break;
    }
}


@end
